{% extends base_template %}

{% block title %}
    {{ '日志'|trans({'%name%': admin.toString(object)|truncate(15) }, 'SonataAdminBundle') }}
{% endblock %}
{% block navbar_title %}
    {{ 'title_show'|trans({'%name%': admin.toString(object)|truncate(100) }, 'SonataAdminBundle') }}
{% endblock %}
{%- block actions -%}
    {% include '@SonataAdmin/CRUD/action_buttons.html.twig' %}
{%- endblock -%}
{% block tab_menu %}
    {{ knp_menu_render(admin.sidemenu(action), {
        'currentClass' : 'active',
        'template': get_global_template('tab_menu_template')
    }, 'twig') }}
{% endblock %}

{% block show %}
    <div class="info-log-content">
        <div class="filter-area">
            <div class="box box-primary">
                <form class="form-horizontal" action="{{ path('admin_app_info_log', {id: object.id}) }}" method="get">
                    <div class="box-body">
                        <div class="form-group col-lg-3">
                            <label for="filter-version" class="col-sm-2 control-label">Version</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="filter-version" name="version" value="{{ filter.version }}" placeholder="Version">
                            </div>
                        </div>
                        <div class="form-group col-lg-3">
                            <label for="filter-path" class="col-sm-2 control-label">Path</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="filter-path" name="path" value="{{ filter.path }}" placeholder="Path">
                            </div>
                        </div>
                        <div class="form-group col-lg-3">
                            <label for="filter-action" class="col-sm-2 control-label">Action</label>
                            <div class="col-sm-8">
                                <select class="form-control select2" id="filter-action" name="action" placeholder="Action">
                                    <option></option>
                                    <option value=1 {% if filter.action == 1 %}selected="selected"{% endif %}>create</option>
                                    <option value=2 {% if filter.action == 2 %}selected="selected"{% endif %}>update</option>
                                    <option value=3 {% if filter.action == 3 %}selected="selected"{% endif %}>remove</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="pull-right">
                            <button type="submit" class="btn btn-primary">
                                <i class="fa fa-filter" aria-hidden="true"></i> 过滤
                            </button>
                            <a class="btn btn-default"
                               href="{{ path('admin_app_info_log', {id: object.id, filters: 'reset'}) }}"> 重置 </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <ul class="timeline">
            {% if pagination.getTotalItemCount > 0 %}
                {% for log in pagination %}
                    <li class="time-label">
                        <span class="bg-green" style="padding: 5px 10px">{{ log.version }}</span>
                    </li>
                    {% for item in log.data %}
                        <li>
                            {% if item.action == 1 %}
                                <i class="fa fa-plus bg-aqua"></i>
                            {% elseif item.action == 2 %}
                                <i class="fa fa-retweet bg-teal"></i>
                            {% else %}
                                <i class="fa fa-trash bg-red"></i>
                            {% endif %}
                            <div class="timeline-item">
                                <span class="time"><i class="fa fa-clock-o"></i> {{ item.date|date('Y-m-d H:i:s', 'PRC') }}</span>
                                <span class="time"><i class="fa fa-user-o"></i> {{ admin_users[item.adminId] }}</span>
                                <h3 class="timeline-header">
                                    <a href="javascript:void(0)">{{ item.path }}</a>
                                    <code>{% if item.action == 1 %}新增{% elseif item.action == 2 %}更新{% else %}移除{% endif %}</code>
                                </h3>
                                <div class="timeline-body">
                                    {% set body_data = json_decode(item.body) %}
                                    {% if body_data.basic|length > 0 %}
                                        <fieldset>
                                            <legend>Basic</legend>
                                            <div class="box-body no-padding">
                                                <table class="table table-condensed">
                                                    <tbody>
                                                    <tr>
                                                        <th style="width: 150px">key</th>
                                                        <th>description</th>
                                                    </tr>
                                                    {% for key,value in body_data.basic %}
                                                        {% if value|length > 0 %}
                                                            <tr>
                                                                <td>{{ key }}</td>
                                                                <td>{{ value|raw }}</td>
                                                            </tr>
                                                        {% endif %}
                                                    {% endfor %}
                                                    </tbody>
                                                </table>
                                            </div>
                                        </fieldset>
                                    {% endif %}
                                    {% if body_data.field|length > 0 %}
                                        <fieldset>
                                            <legend>Field</legend>
                                            <div class="box-body no-padding">
                                                <table class="table table-condensed">
                                                    <tbody>
                                                    <tr>
                                                        <th style="width: 100px">type</th>
                                                        <th style="width: 100px">action</th>
                                                        <th style="width: 150px">key</th>
                                                        <th>description</th>
                                                        <th>format</th>
                                                        <th>required</th>
                                                    </tr>
                                                    {% for field_item in body_data.field %}
                                                        <tr>
                                                            <td>{{ field_item.type }}</td>
                                                            <td>{{ field_item.action }}</td>
                                                            <td>{{ field_item.key }}</td>
                                                            <td>{% if field_item.description is defined %}{{ field_item.description|raw }}{% else %}-{% endif %}</td>
                                                            <td>{% if field_item.format is defined %}{{ field_item.format|raw }}{% else %}-{% endif %}</td>
                                                            <td>{% if field_item.required is defined %}{{ field_item.required|raw }}{% else %}-{% endif %}</td>
                                                        </tr>
                                                    {% endfor %}
                                                    </tbody>
                                                </table>
                                            </div>
                                        </fieldset>
                                    {% endif %}
                                </div>
                            </div>
                        </li>
                    {% endfor %}
                    {% if log.data|length == 3 and filter.version is empty %}
                        <li>
                            <div class="more">
                                <a href="{{ path('admin_app_info_log', {id: object.id, version: log.version}) }}">
                                    查看更多 </a>
                            </div>
                        </li>
                    {% endif %}
                {% endfor %}
            {% else %}
                <li>
                    <div class="more">暂无数据</div>
                </li>
            {% endif %}
        </ul>
        <div class="text-center">
            {{ knp_pagination_render(pagination) }}
        </div>
    </div>
{% endblock %}
